package edu.xkd.slice;

import edu.xkd.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;

public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        // 获取按钮对象
        Button button01_01 = (Button) this.findComponentById(ResourceTable.Id_button01_01);

        // 跳转到第二个ability里
        button01_01.setClickedListener(this::ClickedListenerButton01_01);
    }

    private void ClickedListenerButton01_01(Component component) {
        Intent intent = new Intent();
        Operation operation = new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName("edu.xkd")
                .withAbilityName("edu.xkd.SecordAbility")
                .build();

        // 把operation设置到intent中
        intent.setOperation(operation);
        startAbility(intent);

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
